package com.harry.example2;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class Example2Application {

    public static void main(String[] args) {
        SpringApplication.run(Example2Application.class,args);
    }

    @RestController
    public class EchoController {
        @Autowired
        private Environment env;

        @Autowired
        private RestTemplate restTemplate;

        @GetMapping(value = "/echo/{string}")
        public String echo(@PathVariable String string) {
            return "Hello Nacos Discovery " + string;
        }

        @GetMapping("/testRemote")
        public String testRemote(){

            System.out.println("Example2Application "+env.getProperty("server.port")+" 被调用");
            return "Example2Application "+env.getProperty("server.port")+" 被调用";
        }
    }


    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder){
        return restTemplateBuilder.build();
    }
}
